/*
 * TreeCellRenderer.java
 *
 * Created on 29 February 2004, 04:12
 * Copyright (C) 2004, Velocityme Partnership
 */

package com.velocityme.client;

import com.velocityme.client.gui.GuiTreeNode;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

/**
 *
 * @author  Robert Crida Work
 */
public class GuiTreeCellRenderer extends JLabel implements TreeCellRenderer {
    
    private ImageIcon m_noteIcon;
    private ImageIcon m_nodeOpenIcon;
    private ImageIcon m_nodeClosedIcon;
    private ImageIcon m_systemNodeOpenIcon;
    private ImageIcon m_systemNodeClosedIcon;
    private ImageIcon m_projectIcon;
    private ImageIcon m_projectResolvedIcon;
    private ImageIcon m_anchorIcon;
    private ImageIcon m_actionIcon;
    private ImageIcon m_actionResolvedIcon;
    private ImageIcon m_issueIcon;
    private ImageIcon m_issueResolvedIcon;
    private ImageIcon m_organisationIcon;
    private ImageIcon m_departmentIcon;
    private ImageIcon m_personIcon;
    private ImageIcon m_userIcon;
    private ImageIcon m_userEnabledIcon;
    private ImageIcon m_groupIcon;
    private ImageIcon m_taskTypeIcon;
    private ImageIcon m_stateIcon;
    private ImageIcon m_statusIcon;
    private ImageIcon m_roleIcon;
    private ImageIcon m_contactDetailIcon;
    private ImageIcon m_systemPropertyIcon;
    private ImageIcon m_licenceManagementIcon;
    private ImageIcon m_loginHistoryIcon;
    private ImageIcon m_directoryIcon;
    private Icon m_openIcon, m_closedIcon, m_leafIcon;
    
    /** Creates a new instance of TreeCellRenderer */
    public GuiTreeCellRenderer(Icon p_open, Icon p_closed, Icon p_leaf) {
        m_noteIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/note-16x16.png"));
        m_nodeOpenIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/node-16x16.png"));
        m_nodeClosedIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/node-close-16x16.png"));
        m_systemNodeOpenIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/systemnode-16x16.png"));
        m_systemNodeClosedIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/systemnode-close-16x16.png"));
        m_projectIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/project-16x16.png"));
        m_projectResolvedIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/project-resolved-16x16.png"));
        m_anchorIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/anchor-16x16.png"));
        m_actionIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/action-16x16.png"));
        m_actionResolvedIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/action-resolved-16x16.png"));
        m_issueIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/issue-16x16.png"));
        m_issueResolvedIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/issue-resolved-16x16.png"));
        m_organisationIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/organisation-16x16.png"));
        m_departmentIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/department-16x16.png"));
        m_personIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/person-16x16.png"));
        m_userIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/user-16x16.png"));
        m_userEnabledIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/user-enabled-16x16.png"));
        m_groupIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/group-16x16.png"));
        m_taskTypeIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/task-16x16.png"));
        m_stateIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/state-16x16.png"));
        m_statusIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/status-16x16.png"));
        m_roleIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/role-16x16.png"));
        m_contactDetailIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/contactdetail-16x16.png"));
        m_systemPropertyIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/systemproperty-16x16.png"));
        m_licenceManagementIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/licencemanagement-16x16.png"));
        m_loginHistoryIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/loginhistory-16x16.png"));
        m_directoryIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/directory-16x16.png"));
        m_openIcon = p_open;
        m_closedIcon = p_closed;
        m_leafIcon = p_leaf;
    }
    
    public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        setText(value.toString());
        if (value instanceof DefaultMutableTreeNode) {
            Object uo = ((DefaultMutableTreeNode)value).getUserObject();
            if (uo instanceof GuiTreeNode) {
                GuiTreeNode guiTreeNode = (GuiTreeNode)uo;
                String nodeType = guiTreeNode.getType();
                if (nodeType.equals("Node")) {
                    if (expanded)
                        setIcon(m_nodeOpenIcon);
                    else
                        setIcon(m_nodeClosedIcon);
                }
                else if (nodeType.equals("SystemNode")) {
                    if (expanded)
                        setIcon(m_systemNodeOpenIcon);
                    else
                        setIcon(m_systemNodeClosedIcon);
                }
                else if (nodeType.equals("Project")) {
                    if (guiTreeNode.isActive())
                        setIcon(m_projectIcon);
                    else
                        setIcon(m_projectResolvedIcon);
                }
                else if (nodeType.equals("Anchor")) {
                    setIcon(m_anchorIcon);
                }
                else if (nodeType.equals("Action")) {
                    if (guiTreeNode.isActive())
                        setIcon(m_actionIcon);
                    else
                        setIcon(m_actionResolvedIcon);
                }
                else if (nodeType.equals("Issue")) {
                    if (guiTreeNode.isActive())
                        setIcon(m_issueIcon);
                    else
                        setIcon(m_issueResolvedIcon);
                }
                else if (nodeType.equals("Organisation")) {
                    setIcon(m_organisationIcon);
                }
                else if (nodeType.equals("Department")) {
                    setIcon(m_departmentIcon);
                }
                else if (nodeType.equals("Person")) {
                    setIcon(m_personIcon);
                }
                else if (nodeType.equals("User")) {
                    if (guiTreeNode.isActive())
                        setIcon(m_userEnabledIcon);
                    else
                        setIcon(m_userIcon);
                }
                else if (nodeType.equals("Group")) {
                    setIcon(m_groupIcon);
                }
                else if (nodeType.equals("TaskStateMachine")) {
                    setIcon(m_taskTypeIcon);
                }
                else if (nodeType.equals("State")) {
                    setIcon(m_stateIcon);
                }
                else if (nodeType.equals("Status")) {
                    setIcon(m_statusIcon);
                }
                else if (nodeType.equals("Role")) {
                    setIcon(m_roleIcon);
                }
                else if (nodeType.equals("Note")) {
                    setIcon(m_noteIcon);
                }
                else if (nodeType.equals("ContactDetailTypes")) {
                    setIcon(m_contactDetailIcon);
                }
                else if (nodeType.equals("SystemProperties")) {
                    setIcon(m_systemPropertyIcon);
                }
                else if (nodeType.equals("LicenceManagement")) {
                    setIcon(m_licenceManagementIcon);
                }
                else if (nodeType.equals("LoginHistory")) {
                    setIcon(m_loginHistoryIcon);
                }
                else if (nodeType.equals("Directory")) {
                    setIcon(m_directoryIcon);
                }
                else {
                    if (expanded)
                        setIcon(m_openIcon);
                    else if (leaf)
                        setIcon(m_leafIcon);
                    else
                        setIcon(m_closedIcon);
                }
            }
            else
                setText(uo.getClass().getName());
        }
        else
            setText(value.getClass().getName());
        setOpaque(selected);
        return this;
    }
    
}
